﻿using System;
using System.Collections.Generic;
using System.Linq;
using Web.Models.CoreData;


namespace Web.ViewModel.CoreData
{
    /// <summary>
    /// 终端模型
    /// </summary>
    public class UserModel
    {
        /// <summary>
        /// 数据标识
        /// </summary>
        public String Id { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public String UserName { get; set; }
        /// <summary>
        /// 许可号
        /// </summary>
        public String Account { get; set; }
        /// <summary>
        /// mmsi
        /// </summary>
        public String MMSI { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public String Password { get; set; }
        /// <summary>
        /// 公司名
        /// </summary>
        public String CompanyName { get; set; }
        /// <summary>
        /// 公司ID
        /// </summary>
        public String Company { get; set; }
        

        /// <summary>
        /// 注册码
        /// </summary>
        public String Register { get; set; }
        /// <summary>
        /// 配置项id
        /// </summary>
        public String Configs { get; set; }


        public UserModel()
        {
            
        }
        /// <summary>
        /// 模型转换
        /// </summary>
        /// <param name="user"></param>
        /// <param name="companies"></param>
        /// <returns></returns>
        public UserModel ConvertModel(User user, List<Company> companies=null)
        {
            return new UserModel()
            {
                Account = user.Account,
                UserName = user.UserName,
                CompanyName = companies == null ? "" : companies.FirstOrDefault(m => m.Id == user.Company)?.Name,
                Company = user.Company,
                Id = user.Id,
                MMSI = user.MMSI,
                Password = user.Password,
                Register=user.Register,
                Configs = user.Configs
            };
        }

    }

  
}
